package com.kaifamiao.schema;

import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;

// ThrowsAdvice 继承了 org.springframework.aop.AfterAdvice 接口
// org.springframework.aop.AfterAdvice 继承了 org.aopalliance.aop.Advice
public class PandaThrowsAdvice implements ThrowsAdvice {

    // afterThrowing( [Method, args, target], subclassOfThrowable )

    /*
    // 仅有一个异常类型的参数
    public void afterThrowing( Throwable th ) {
        System.out.println( "呀，出错了: " + th.getMessage() );
    }
    */

    public void afterThrowing(Method m, Object[] args, Object target, Throwable th ) {
        String name = m.getName();
        System.out.println( "【" + name + "】方法执行时发生异常: " + th.getMessage() );
    }

}
